<?php
namespace app\admin\model;


use think\facade\Cache;
use think\Model;

class GoodsProp extends Model
{
    public function searchKeywordsAttr($query,$value,$data)
    {
        if (''!== $value){
            $query->whereLike('pname','%'.$value.'%');
        }
    }
    public function searchPropValueAttr($query,$value,$data)
    {
        if (is_array($value) && count($value) > 0){
            foreach($value as $v){
                $query->whereFindInSet('pvalues',$v);
            }
        }
    }
    public function searchPropValueKeyword(){

    }
    public static function getPropValueArr(){
        if (Cache::has('prop_value_arr')){
            return Cache::get('prop_value_arr');
        }
    }

    protected $pk ='pid';

        public static function getAttriBute($data = [],$query = [],$page = false) {

            $model=self::field(true)
                ->withSearch(array_keys($data),$data);

//            if (isset($data['prop_value'])&&is_array($data['prop_value']) && count($data['prop_value'])>0){
//                foreach($data['prop_value'] as $v){
//                    $model->where('pvalues','find in set',$v);
//                }
//            }
//            if(isset($data['keywords'])&&'' !== $data['keywords']){
//                $model->where('pname','like','%'.$data['keywords'].'%');
//            }
//            $list_rows = Config::has('view.list_rows')?Config::get('view.list_rows'):15;

            if($page){
                $result=$model->select();
            }else{
                $result=$model->paginate([
                    'list_rows' =>3,
                    'query'=>$query,
                ]);
            }
            return $result;
        }

}